﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace BasicFrameworkDemo.Web.Model
{
    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
    public sealed class ValidatePasswordLengthAttribute : ValidationAttribute, IClientValidatable
    {
        //private const string _defaultErrorMessage = "'{0}' must be at least {1} characters long.";
        //private readonly int _minCharacters = Membership.Provider.MinRequiredPasswordLength;

        public ValidatePasswordLengthAttribute()
            : base(string.Empty)
        {
        }

        public string FormatErrorMessage(string name, int maxValue)
        {
            return String.Format(CultureInfo.CurrentCulture, ErrorMessageString,
                name);
        }

        public override bool IsValid(object value)
        {
            string valueAsString = value as string;
            return (valueAsString != null );
        }

        public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            //return new[]{
            //    new ModelClientValidationStringLengthRule(FormatErrorMessage(metadata.GetDisplayName(), int.MaxValue,int.MaxValue))
            //};

            return null;
        }
    }
}
